/**
 * 抛出一个 SliderV 对象，含有两个函数：
 * 		init: function (param)
 * 			param：{ verifyUrl：验证接口的调用地址；callback（理论可选，按往往必要)：验证成功的回调；failCB（可选）：验证失败的回调；successInfo（可选）：验证通过时的提示文字；failInfo（可选）：验证失败时的提示文字 }
 * 		show: function 显示出	验证弹窗
 * 		hide: function 隐藏 验证弹窗
 * 	注意：
 * 		获取短信验证码时：
 * 			successInfo：“验证成功，速度惊人！短信已下发！”,
 * 			failInfo：“验证失败，拖动按钮完成拼图获取短信！”
 * 		其他操作失根据后续操作灵活改变。
 * 		请保证 show 的调用在 init 之后
 */
if(window) {
	if(window.sliderV) {
		throw new Error('变量 SliderValidation 被占用');
	} else {
		// 兼容帧动画能力
		(function() {
			var lastTime = 0;
			var vendors = ['ms', 'moz', 'webkit', 'o'];
			for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
				window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
				window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame']
					|| window[vendors[x]+'CancelRequestAnimationFrame'];
			}

			if (!window.requestAnimationFrame)
				window.requestAnimationFrame = function(callback, element) {
					var currTime = new Date().getTime();
					var timeToCall = Math.max(0, 16 - (currTime - lastTime));
					var id = window.setTimeout(function() { callback(currTime + timeToCall); },
						timeToCall);
					lastTime = currTime + timeToCall;
					return id;
				};

			if (!window.cancelAnimationFrame)
				window.cancelAnimationFrame = function(id) {
					clearTimeout(id);
				};
		}());

		window.sliderV = (function (doc, win) {
			var screenWidth = window.innerWidth, screenHeight = window.innerHeight, sliderV = this,
				d= { x: 0, y: 0},
				mouse = { x: 0, y: 0 },
				ctrlBarBounding, singleFlag = false, canTrag = true,
				oCtrlBlock, oCtrlImg, oImgBg, oImgWrapper, oInfoWrapper, oDivWrapper, oGif, // 控制块、受控拼图、背景图片，图片容器元素、提示信息容器元素、顶层容器
				curLeft, token, isFirst = true;;

			/**
			 * 对外抛出的初始化函数
			 * @param {Object} param 初始化验证码码
			 */
			sliderV.init = function (param) {
				if(singleFlag) { throw new Error('请不要重复初始化') }
				option = {
					verifyUrl: param.verifyUrl || '',
					callback: param.callback || function () {},
					failCB: param.failCB || function () {},
					successInfo: param.successInfo || '验证成功',
					failInfo: param.failInfo || '验证失败'
				};
				buildHTML();
				document.body.appendChild(oDivWrapper);
				getInfo();
				// 保持单例
				singleFlag = true;
			};

			/**
			 * 对外抛出的显示函数
			 */
			sliderV.show = function () {
				if(singleFlag) {
					oDivWrapper.style.display = 'block';
					if(!isFirst) {
						getInfo();
					} else {
						isFirst = !isFirst;
					}
				}
			};

			/**
			 * 对外抛出隐藏函数
			 */
			sliderV.hide = function () {
				oDivWrapper.style.display = 'none';
			};

			/**
			 * 以动画形式显示提示文本
			 * @param {String} text 提示信息字符串
			 */
			function showInfo (text) {
				oInfoWrapper.innerText = text || '';
				if(arguments[1] && typeof arguments[1] === 'object') {
					for(var keyS in arguments[1]) {
						if(arguments[1].hasOwnProperty(keyS)) {
							oInfoWrapper.style[keyS] = arguments[1][keyS];
						}
					}
				}
				var cb = arguments[2] || function () {};
				var timeout = arguments[3] || 1000;
				playAnimation(function () {
					var curBottom = parseFloat(oInfoWrapper.style.bottom);
					curBottom += 1.5;
					if(curBottom < 0) {
						oInfoWrapper.style.bottom = curBottom + '%';
						return false;
					} else {
						oInfoWrapper.style.bottom = '0%';
						setTimeout(cb, timeout);
						return true;
					}
				});
				setTimeout(function () { // 5秒后隐藏
					hideInfo();
				}, 5000);
			}

			/**
			 * 以动画形式隐藏提示
			 */
			function hideInfo () {
				playAnimation(function () {
					var curBottom = parseFloat(oInfoWrapper.style.bottom);
					curBottom -= 1.5;
					if(curBottom < -20) {
						oInfoWrapper.style.bottom = '-20%';
						return true;
					} else {
						oInfoWrapper.style.bottom = curBottom + '%';
						return false;
					}
				})
			}

			/**
			 * 以动画的形式重置left属性
			 */
			function setZeorLeft () {
				playAnimation(function () {
					var curLeft = parseFloat(oCtrlBlock.style.left);
					curLeft -= 20;
					if(curLeft > 0) {
						oCtrlBlock.style.left = curLeft + 'px';
						oCtrlImg.style.left = curLeft + 'px';
					} else {
						oCtrlBlock.style.left = '0px';
						oCtrlImg.style.left = '0px';
						return true;
					}
				})
			}

			/**
			 * 获取后台数据进行初始化
			 */
			function getInfo () {
				sendAjax({
					url: '/users/getInfo',
					type: 'post',
					dataType: 'json',
					success: function (res) {
						if(res.retCode === '0') {
							token = res.token;
							canTrag = true;
							if(oImgBg && oCtrlImg) {
								oImgWrapper.removeChild(oImgBg);
								oImgWrapper.removeChild(oCtrlImg);
							}
							if(oCtrlBlock && oCtrlImg) {
								setZeorLeft(); // 重置 控制块 和 受控拼图 位置
							}
							// 背景图片
							oImgBg = createEle('img', {
								attr: {
									id: 'oBgImg',
									src: 'data:image/png;base64,' + res.origin,
									alt: '背景'
								},
								style: {
									width: '100%'
									// height: height * .55 + 'px'
								},
								events: {
									load: function () {
										oImgWrapper.appendChild(oImgBg);
									}
								}
							});
							// 受控图片
							oCtrlImg = createEle('img', {
								attr: {
									id: 'ctrlImg',
									src: 'data:image/png;base64,' + res.target,
									alt: '拼图'
								},
								style: {
									position: 'absolute',
									left: '0',
									'z-index': '10'
									//width: '8.89%'
									// height: height * .19 + 'px'
								},
								events: {
									load: function () {
										oImgWrapper.appendChild(oCtrlImg);
										this.style.width = this.naturalWidth / oImgBg.naturalWidth * 100 + '%';
										this.style.top = res.height / oImgBg.naturalHeight * 100 + '%';
									}
								}
							});
							oImgWrapper.appendChild(oImgBg);
							oImgWrapper.appendChild(oCtrlImg);
						} else {
							showInfo('接口结果异常，初始化失败', {
								color: 'red'
							})
						}
					}
				})
			}

			/**
			 * 发送验证请求
			 */
			function postVerify () {
				canTrag = false;
				var curWidth = oImgBg.getBoundingClientRect().width;
				sendAjax({
					url: option.verifyUrl,
					type: 'post',
					data: {
						token: token,
						ratio: (curLeft / curWidth).toFixed(4)
					},
					dataType: 'text',
					success: function (res) {
						// ============= 测试用例
						// res = '2';
						// =============
						if(res === '2') { // 每两次重新请求一次图片
							showInfo('图片被怪兽拖走了~请重新验证', {
								color: '#00bbff'
							}, getInfo);
							canTrag = true;
						} else if (res === '0') {
							showInfo(option.successInfo, {
								color: '#09BB07'
							}, option.callback, 2500);
						} else {
							showInfo(option.failInfo, {
								color: 'red'
							}, option.failCB);
							setZeorLeft();
							canTrag = true;
						}
					},
					error: function (res) {
						showInfo('出错啦，三秒后重试', {
							color: 'red'
						}, getInfo, 3000);
					}
				})
			}

			/**
			 * 控制块 touchstart处理函数
			 * @param {Object} event touchstart事件对象
			 */
			function ctrlBlockTouchStart (event) {
				var e = event || window.event;
				if(canTrag) {
					var ctrlBlockBounding = e.target.getBoundingClientRect();
					d.x = e.changedTouches[0].clientX - ctrlBlockBounding.left;
					doc.addEventListener('touchmove', docTouchMove, false);
					doc.addEventListener('touchend', docTouchEnd, false);
					ctrlBarBounding = document.getElementById('ctrlBar').getBoundingClientRect();
				}
			}

			/**
			 * 整个文档流 touchmove处理函数
			 * @param {Object} event touchmove事件对象
			 */
			function docTouchMove (event) {
				var e = event || window.event;
				e.stopPropagation();
				mouse.x = e.changedTouches[0].clientX;
				var ctrlBlockWidth = parseFloat(oCtrlBlock.style.width);
				curLeft = mouse.x - ctrlBarBounding.left - d.x;
				// var percentage = curLeft / (ctrlBarBounding.width - ctrlBlockWidth) * 100;
				// var maxPercentage = (ctrlBarBounding.width - ctrlBlockWidth) / ctrlBarBounding.width * 100;
				// 绝对值
				if (curLeft <= 0) {
					curLeft = 0;
				} else if (curLeft >= ctrlBarBounding.width - ctrlBlockWidth) {
					curLeft = ctrlBarBounding.width - ctrlBlockWidth;
				}
				oCtrlBlock.style.left = curLeft + 'px';
				oCtrlImg.style.left = curLeft + 'px';
				// 百分比
				// if(percentage > 0 && percentage < maxPercentage) {
				//     oCtrlBlock.style.left = percentage + '%';
				//     oCtrlImg.style.left = percentage + '%';
				// } else if (percentage <= 0) {
				//     oCtrlBlock.style.left = '0%';
				//     oCtrlImg.style.left = '0%';
				// } else if (percentage >= maxPercentage) {
				//     oCtrlBlock.style.left = maxPercentage + '%';
				//     oCtrlImg.style.left = maxPercentage + '%';
				// }
				return false;
			}

			/**
			 * 文档流的 touchend 处理函数
			 * @param {Object} event touchend事件对象
			 */
			function docTouchEnd (event) {
				var e = event || window.event;
				doc.removeEventListener('touchmove', docTouchMove);
				doc.removeEventListener('touchend', docTouchEnd);
				postVerify()
			}

			/**
			 * 构建滑块验证的HTML，CSS和事件绑定
			 */
			function buildHTML () {
				var height = screenWidth * .8 * 2 / 3 ;
				// 顶层容器
				oDivWrapper = createEle('div', {
					style: {
						position: 'absolute',
						top: '0', left: '0', right: '0', bottom: '0',
						'z-index': '1000',
						'font-size': '100px',
						display: 'none'
					}
				});
				// 背景遮罩
				var oDivMask = createEle('div', {
					style: {
						position: 'absolute',
						width: '100%',
						height: '100%',
						background: 'rgba(0, 0, 0, .45)',
						'z-index': '-1'
					}
				});
				// 内容容器
				var oDivContent = createEle('div', {
					style: {
						width: '80%',
						// height: height + 'px',
						margin: '1.5em auto 0',
						'background-color': 'white',
						padding: height * .075 + 'px ' + height * .075 + 'px ' + height * .1 + 'px',
						'box-sizing': 'border-box',
						'border-radius': '.1em'
					}
				});
				// 图片容器
				oImgWrapper = createEle('div', {
					attr: {
						id: 'imgWrapper'
					},
					style: {
						width: '100%',
						// height: '75%',
						'background-color': '#eee',
						'box-sizing': 'border-box',
						position: 'relative',
						'font-size': '0',
						overflow: 'hidden'
					}
				});
				// 教学使用的gif图片
				oGif = createEle("img", {
					attr: {
						src: '/images/138176_1422517408VD82.gif',
						alt: '指导'
					},
					style: {
						width: '100%',
						height: '100%',
						position: 'absolute',
						top: '0',
						'z-index': '12',
						display: 'none'
					},
					events: {
						load: function () {
							oImgWrapper.appendChild(this);
						}
					}
				})

				// 工具条容器
				var toolBarHeight = height * .15; // 工具条高度
				var btnsWH = height * .075; // 按钮宽高
				var btnsMargin = height * .0375; // 按钮margin
				var oToolBar = createEle('div', {
					style: {
						width: '100%',
						height: toolBarHeight + 'px',
						background: '#eee',
						'font-size': '0'
					}	
				});
				// 刷新按钮svg元素
				var oSvgRefresh = createEle('svg', {
					attr: {
						viewBox: '0 0 1024 1024',
						xmlns: 'http://www.w3.org/2000/svg',
						'xmlns:xlink': 'http://www.w3.org/1999/xlink',
						'width': btnsWH,
						'height': btnsWH
					},
					style: {
						fill: '#aaa',
						margin: btnsMargin + 'px'
					},
					events: {
						click: function () {
							getInfo();
						}
					}
				}, 'svg');
				// 刷新按钮路径元素
				var oRefreshPath = createEle('path', {
					attr: {
						d: 'M55.935033 264.48948c0 0 85.897017-132.548409 221.81443-203.673173 135.916406-71.121743 303.368504-50.646859 413.187968 18.319527 109.819465 68.970415 146.791894 127.160016 146.791894 127.160016l94.59499-53.879895c0 0 19.576483-9.697092 19.576483 12.932142l0 338.379961c0 0 0 30.17399-22.837719 19.395191-19.210878-9.062571-226.959086-127.198289-292.424528-164.466828-35.950145-16.035251-4.365101-29.062068-4.365101-29.062068l91.284402-52.173738c0 0-52.068992-65.209619-128.278989-99.744682-81.576231-42.501826-157.948384-47.541735-251.497925-12.224097-61.002644 23.025054-132.823368 81.988166-184.553949 169.082716L55.935033 264.48948 55.935033 264.48948 55.935033 264.48948zM904.056909 711.697844c0 0-85.897017 132.550423-221.816444 203.671159-135.917413 71.12275-303.366489 50.651895-413.186961-18.315498-109.825508-68.972429-146.790886-127.165052-146.790886-127.165052L27.662591 823.768348c0 0-19.572454 9.703135-19.572454-12.932142L8.090137 472.459267c0 0 0-30.170968 22.831676-19.397205 19.211885 9.067607 226.965129 127.198289 292.430571 164.470856 35.950145 16.035251 4.366109 29.058039 4.366109 29.058039l-91.285409 52.175753c0 0 52.071006 65.206598 128.279996 99.744682 81.57321 42.498804 157.942341 47.540728 251.496918 12.222082 60.998616-23.026061 132.820346-81.983131 184.546898-169.082716L904.056909 711.697844 904.056909 711.697844 904.056909 711.697844zM904.056909 711.697844'
					}
				}, 'svg');
				oSvgRefresh.appendChild(oRefreshPath);
				// 问号按钮svg元素
				var oSvgQuestion = createEle('svg', {
					attr: {
						viewBox: '0 0 1024 1024',
						xmlns: 'http://www.w3.org/2000/svg',
						'xmlns:xlink': 'http://www.w3.org/1999/xlink',
						'width': btnsWH,
						'height': btnsWH
					},
					style: {
						fill: '#aaa',
						margin: btnsMargin + 'px'
					},
					events: {
						click: function () {
							console.log(oGif);
							oGif.style.display = oGif.style.display === 'block' ? 'none' : 'block';
						}
					}
				}, 'svg');
				// 问号按钮路径元素1
				var oQuestionPath1 = createEle('path', {
					attr: {
						d: 'M512.001251 0C229.230705 0 0 229.230705 0 512.001251c0 282.769295 229.231956 512 512.001251 512S1024.002503 794.770547 1024.002503 512.001251C1024.002503 229.230705 794.771798 0 512.001251 0L512.001251 0zM512.001251 959.882069c-247.357599 0-447.880818-200.523219-447.880818-447.880818 0-247.35885 200.521968-447.880818 447.880818-447.880818S959.882069 264.642401 959.882069 512.001251C959.882069 759.35885 759.35885 959.882069 512.001251 959.882069L512.001251 959.882069z'
					}
				}, 'svg');
				// 问号按钮路径元素2
				var oQuestionPath2 = createEle('path', {
					attr: {
						d: 'M412.335238 403.381275c0 0 16.059826-98.832679 114.893756-87.71405 98.832679 11.119881 76.594169 85.244077 66.711777 100.068917C584.057127 440.444625 492.636868 499.743982 477.812029 535.571094c-14.824839 35.827112-13.589853 102.538889-13.589853 102.538889l88.950287 0c0 0-4.942447-70.417987 44.474518-100.068917 49.416965-29.649679 133.423554-116.127491 96.361456-198.900345-59.299357-95.126469-117.363728-105.010113-192.722911-102.538889-75.360434 2.471224-154.427078 39.532071-180.370547 154.424575C382.685559 399.675065 412.335238 403.381275 412.335238 403.381275L412.335238 403.381275z'
					}
				}, 'svg');
				// 问号按钮路径元素3
				var oQuestionPath3 = createEle('path', {
					attr: {
						d: 'M462.987189 707.752193 555.642435 707.752193 555.642435 809.042332 462.987189 809.042332 462.987189 707.752193Z'
					}
				}, 'svg');
				oSvgQuestion.appendChild(oQuestionPath1);
				oSvgQuestion.appendChild(oQuestionPath2);
				oSvgQuestion.appendChild(oQuestionPath3);
				// 关闭按钮svg元素
				var oSvgClose = createEle('svg', {
					attr: {
						viewBox: '0 0 1024 1024',
						xmlns: 'http://www.w3.org/2000/svg',
						'xmlns:xlink': 'http://www.w3.org/1999/xlink',
						'width': btnsWH,
						'height': btnsWH
					},
					style: {
						fill: '#aaa',
						margin: btnsMargin + 'px'
					},
					events: {
						click: function () {
							oDivWrapper.style.display = 'none';
						}
					}
				}, 'svg');
				// 关闭按钮路径元素1
				var oClosePath1 = createEle('path', {
					attr:{
						d: 'M155.252 943.825c-19.213 0-38.429-7.332-53.089-21.988-29.317-29.321-29.317-76.855 0-106.175l713.494-713.494c29.317-29.321 76.853-29.321 106.175 0 29.317 29.317 29.317 76.855 0 106.175l-713.494 713.494c-14.66 14.66-33.874 21.988-53.089 21.988z'
					}
				}, 'svg');
				// 关闭按钮路径元素2
				var oClosePath2 = createEle('path', {
					attr: {
						d: 'M868.749 943.824c-19.213 0-38.428-7.332-53.089-21.988l-713.494-713.493c-29.317-29.317-29.317-76.857 0-106.175 29.316-29.317 76.855-29.321 106.174 0l713.494 713.492c29.317 29.321 29.317 76.855 0 106.175-14.657 14.661-33.871 21.993-53.087 21.993z'
					}
				}, 'svg');
				oSvgClose.appendChild(oClosePath1);
				oSvgClose.appendChild(oClosePath2);

				// 提示容器
				oInfoWrapper = createEle('div', {
					style: {
						width: '100%',
						height: '20%',
						position: 'absolute',
						bottom: '-20%',
						background: 'rgba(255, 255, 255, .75)',
						'font-size': height *.065 + 'px',
						display: 'flex',
						'justify-content': 'center',
						'align-items': 'center'
					}
				});

				// 控制条
				var oDivCtrlBar = createEle('div', {
					attr: {
						id: 'ctrlBar'
					},
					prop: {
						innerText: '按住滑块，拖动完成上方拼图'
					},
					style: {
						width: '100%',
						height: height * .125 + 'px',
						'background-color': '#eee',
						'border-radius': height * .125 + 'px',
						border: height * .0025 + 'px solid #aaa',
						'margin': '1.5em auto 0',
						position: 'relative',
						'text-align': 'center',
						'line-height': height * .125 + 'px',
						color: '#666',
						'font-size': height * .05 + 'px',
						'z-index': '11'
					}
				});
				// 控制块
				oCtrlBlock = createEle('div', {
					attr: {
						id: 'ctrlBlock'
					},
					style: {
						width: height * .19 + 'px',
						height: height * .19 + 'px',
						'background-color': 'white',
						'border-radius': '50%',
						position: 'absolute',
						top: '50%',
						left: '0',
						'margin-top': '-' + height * .19 * .5 + 'px',
						'box-shadow': '0 0 1em .2em #666'
					},
					events: {
						touchstart: ctrlBlockTouchStart
					}
				});
				// SVG模块，拖拽标志
				var oCtrlBlockWidth = parseFloat(oCtrlBlock.style.width);
				var oCtrlBlockHeight = parseFloat(oCtrlBlock.style.height);
				var oSVGDrag = createEle('svg', {
					attr: {
						viewBox: '0 0 1024 1024',
						xmlns: 'http://www.w3.org/2000/svg',
						'xmlns:xlink': 'http://www.w3.org/1999/xlink',
						'width': oCtrlBlockWidth * .7,
						'height': oCtrlBlockHeight
					}
				}, 'svg');
				// 路径元素
				var oDragPath = createEle('path', {
					attr: {
						d: 'M896 544 128 544C110.32 544 96 529.68 96 512 96 494.32 110.32 480 128 480L896 480C913.68 480 928 494.32 928 512 928 529.68 913.68 544 896 544ZM896 224 128 224C110.32 224 96 209.68 96 192 96 174.32 110.32 160 128 160L896 160C913.68 160 928 174.32 928 192 928 209.68 913.68 224 896 224ZM128 800 896 800C913.68 800 928 814.32 928 832 928 849.68 913.68 864 896 864L128 864C110.32 864 96 849.68 96 832 96 814.32 110.32 800 128 800Z'
					},
					style: {
						fill: '#aaa'
					}
				}, 'svg');
				oSVGDrag.appendChild(oDragPath);

				oCtrlBlock.appendChild(oSVGDrag);
				oDivCtrlBar.appendChild(oCtrlBlock);
				oToolBar.appendChild(oSvgRefresh);
				oToolBar.appendChild(oSvgQuestion);
				oToolBar.appendChild(oSvgClose);
				oImgWrapper.appendChild(oInfoWrapper);

				oDivContent.appendChild(oImgWrapper);
				oDivContent.appendChild(oToolBar);
				oDivContent.appendChild(oDivCtrlBar);

				oDivWrapper.appendChild(oDivMask);
				oDivWrapper.appendChild(oDivContent);
			}

			/**
			 * 创建节点
			 * @param {String} name 节点名
			 * @param {Object} param 参数对象 attr: 待设置的节点属性键值对， style：设置的样式属性键值对
			 * @param {String} name 节点类型dom/svg
			 */
			function createEle(name, param, type) {
				var type = type || 'dom', ele;
				if(type === 'dom') {
					ele = doc.createElement(name);
				} else {
					ele = doc.createElementNS('http://www.w3.org/2000/svg', name);
				}
				if(param.prop && typeof param.prop === 'object') {
					for(var keyP in param.prop) {
						if(param.prop.hasOwnProperty(keyP)) {
							ele[keyP] = param.prop[keyP];
						}
					}
				}
				if(param.attr && typeof param.attr === 'object') {
					for(var keyA in param.attr) {
						if(param.attr.hasOwnProperty(keyA)) {
							ele.setAttribute(keyA, param.attr[keyA]);
						}
					}
				}
				if(param.style && typeof param.style === 'object') {
					for(var keyS in param.style) {
						if(param.style.hasOwnProperty(keyS)) {
							ele.style[keyS] = param.style[keyS];
						}
					}
				}
				if(param.events && typeof param.events === 'object') {
					for(var keyE in param.events) {
						if(param.events.hasOwnProperty(keyE)) {
							ele.addEventListener(keyE, param.events[keyE], false);
						}
					}
				}
				return ele;
			}

			/**
			 * 仿jq的Ajax请求封装
			 * @param {Object} param 仿jq的ajax请求配置
			 */
			function sendAjax (param) {
				var option = {
					url: param.url || '', // 默认无请求路径
					type: param.type || 'GET', // 默认GET请求
					async: param.async || true, // 默认异步
					data: param.data || null, // 默认没有数据
					dataType: param.dataType || 'text', // 默认期待返回数据类型为字符串
					contentType: param.contentType || 'application/x-www-form-urlencoded', // 默认数据内容型为表单类型
					success:param.success || function(){}, // 请求成功返回处理函数
					error:param.error || function(){} // 请求异常失败处理函数
				};
				var xhr = createxmlHttpRequest();
				xhr.responseType = option.dataType;
				xhr.open(option.type, option.url, option.async);
				xhr.setRequestHeader('Content-Type', option.contentType);
				xhr.send(convertData(option.data));
				xhr.onreadystatechange = function () {
					if(xhr.readyState === 4) {
						if(xhr.status === 200) {
							option.success(xhr.response);
						} else {
							option.error(xhr.responseText);
						}
					}
				}
			}

			/**
			 * 创建 xhr 对象
			 */
			function createxmlHttpRequest() {
				if (window.ActiveXObject) {
					return new ActiveXObject("Microsoft.XMLHTTP");
				} else if (window.XMLHttpRequest) {
					return new XMLHttpRequest();
				}
			}

			/**
			 * 将指定参数转化成能被ajax发送的字符串数据
			 * @param {Object || String} data 要转换的数据
			 */
			function convertData (data) {
				if(typeof data === 'object') {
					var convertResult = '';
					for(var key in data) {
						if(data.hasOwnProperty(key)) {
							convertResult += key + '=' + data[key] + '&';
						}
					}
					convertResult = convertResult.substr(0, convertResult.length - 1);
					return convertResult;
				} else {
					return data;
				}
			}

			/**
			 * 帧动画应用封装
			 * @param {Function} cb 要求一定要有boolean类型的返回值，为true表示结束帧动画
			 */
			function playAnimation (cb) {
				var farmeId;
				function tempCb () {
					farmeId = requestAnimationFrame(tempCb); // 放在最前方
					if(cb()) { // 执行完毕
						cancelAnimationFrame(farmeId);
					}
				}
				tempCb();
			}


			return sliderV;
		})(document, window)
	}
} else {
	throw new Error('环境错误，只能在浏览器换将下运行');
}